package api

import (
	"api_gateway/basic/config"
	__ "api_gateway/basic/proto"
	"api_gateway/handler/request"
	"github.com/gin-gonic/gin"
	"net/http"
)

func BrandDirverCar(c *gin.Context) {
	var req request.BrandDirverCar
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "验证失败",
			"data":    err.Error(),
		})
		return
	}
	car, err := config.UserClient.BrandDirverCar(c, &__.BrandDirverCarReq{
		DriverId:      req.DriverId,
		LicenseNumber: req.LicenseNumber,
		Brand:         req.Brand,
		Model:         req.Model,
		Color:         req.Color,
		Seat:          int64(req.Seat),
		CarsUrl:       req.CarsUrl,
	})

	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "绑定失败",
			"data":    err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "绑定成功",
		"data":    car,
	})
}

func CarList(c *gin.Context) {
	var req request.CarList
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "验证失败",
			"data":    err.Error(),
		})
		return
	}
	list, err := config.UserClient.CarTypeList(c, &__.CarTypeListReq{Model: req.Model})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code":    400,
			"message": "车型列表展示失败",
			"data":    err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    200,
		"message": "车型列表展示成功",
		"data":    list,
	})
}
